package com.gitee.pifeng.monitoring.ui.business.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gitee.pifeng.monitoring.ui.business.web.annotation.OperateLog;
import com.gitee.pifeng.monitoring.ui.business.web.service.ITLinkLatestService;
import com.gitee.pifeng.monitoring.ui.business.web.vo.LayUiAdminResultVo;
import com.gitee.pifeng.monitoring.ui.business.web.vo.TLinkLatestVo;
import com.gitee.pifeng.monitoring.ui.constant.OperateTypeConstants;
import com.gitee.pifeng.monitoring.ui.constant.UiModuleConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@Slf4j
@Tag(name = "数据链路")
@RequestMapping("/dataLink")
public class TLinkLatestController {

    @Autowired
    private ITLinkLatestService itLinkLatestService;

    @Operation(summary = "链路测试页面")
    @GetMapping("/test")
    public ModelAndView test() {
        return new ModelAndView("jtopo/visio");
    }

    @Operation(summary = "链路主页")
    @GetMapping("/visHome")
    public ModelAndView visHome() {
        return new ModelAndView("jtopo/visioHome");
    }

    @Operation(summary = "链路详情页面")
    @GetMapping("/visioDetail")
    public ModelAndView jtopoDetail() {
        return new ModelAndView("jtopo/visioDetail");
    }

    @Operation(summary = "操作节点")
    @ResponseBody
    @PostMapping("/operateNode")
    public LayUiAdminResultVo operateNode(@RequestParam(value = "info")String info){
        return itLinkLatestService.operateNode(info);
    }


    @Operation(summary = "获取数据链路错误信息")
    @ResponseBody
    @GetMapping("/getErrMsg")
    public LayUiAdminResultVo getErrMsg(@RequestParam(value = "from")String from,
                                        @RequestParam(value = "to")String to,
                                        @RequestParam(value = "label")String label) {
        return itLinkLatestService.getErrMsg(from, to, label);
    }


    @Operation(summary = "获取数据链路详情")
    @ResponseBody
    @GetMapping("/getDataLink")
    public LayUiAdminResultVo getDataLinkDetail(@RequestParam(value = "showName")String showName) {
        return itLinkLatestService.getDataLinkDetail(showName);
    }

    @Operation(summary = "获取showName")
    @ResponseBody
    @GetMapping("/getShowName")
    public LayUiAdminResultVo getShowName() {
        return itLinkLatestService.getShowName();
    }

    /**
     * <p>
     * 访问数链列表页
     * </p>
     *
     * @return {@link ModelAndView} 访问数链列表页
     * @author wt
     * @custom.date 2023/12/4 13:01
     */
    @Operation(summary = "访问数链列表页")
    @GetMapping("/linkList")
    public ModelAndView linkList() {
        return new ModelAndView("jtopo/latestProcessStat");
    }

    @Operation(summary = "获取数链列表")
    @Parameters(value = {
            @Parameter(name = "current", description = "当前页", required = true, in = ParameterIn.QUERY),
            @Parameter(name = "size", description = "每页显示条数", required = true, in = ParameterIn.QUERY),
            @Parameter(name = "latestProcessStat", description = "状态", in = ParameterIn.QUERY),
            @Parameter(name = "abnormal", description = "异常数量", in = ParameterIn.QUERY),
            @Parameter(name = "showName", description = "数据链路名称", in = ParameterIn.QUERY)
    })
    @GetMapping("get-link-Latest-list")
    @ResponseBody
    public LayUiAdminResultVo getlinkLatestList(@RequestParam(value = "current") Long current,
                                              @RequestParam(value = "size") Long size,
                                              @RequestParam(value = "showName", required = false) String showName,
                                              @RequestParam(value = "latestProcessStat", required = false) String latestProcessStat,
                                              @RequestParam(value = "abnormal", required = false) Integer abnormal) {
        log.info("========2131232132132131========");
        current = (current - 1) * size;
        Page<TLinkLatestVo> page =this.itLinkLatestService.getlinkLatestList(current,size,showName,latestProcessStat,abnormal);
        log.info("========数链page========"+page.getTotal());
         return LayUiAdminResultVo.ok(page);
    }

    @Operation(summary = "删除数据链路")
    @DeleteMapping("/deleteLinkLatest")
    @ResponseBody
    @OperateLog(operModule = UiModuleConstants.DATABASE, operType = OperateTypeConstants.DELETE, operDesc = "删除数据链路")
    public LayUiAdminResultVo deleteLinkLatest(@RequestBody List<TLinkLatestVo> tLinkLatestVos) {
        return itLinkLatestService.deleteLinkLatest(tLinkLatestVos);
    }

}
